import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 组织架构
import departments from '@/router/modules/departments'
// 员工
import employees from '@/router/modules/employees'
// 公司设置
import setting from '@/router/modules/setting'
// 工资
import salarys from '@/router/modules/salarys'
// 社保
import social from '@/router/modules/social'
// 考勤
import attendances from '@/router/modules/attendances'
// 审批
import approvals from '@/router/modules/approvals'
// 权限管理
import permission from '@/router/modules/permission'
// 动态路由
// 具体访问需要token的页面
export const asyncRoutes = [
  // 组织架构
  departments,
  // 公司设置
  setting,
  // 员工
  employees,
  // 权限管理
  permission,
  // 工资
  salarys,
  // 社保
  social,
  // 考勤
  attendances,
  // 审批
  approvals
]
// 静态路由
// 具体访问主页和404
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
  {
    path: '/import',
    component: Layout,
    hidden: true, // 不显示到左侧 不参与遍历
    children: [{
      path: '',
      component: () => import('@/views/import')
    }]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
